<?php
/*
Copyright (C) 2009 de Flotte Maxence

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
?>
<?php

class Zlog_Struct extends Bout {
	
	protected $_autoCreateChildrenRules;

	protected function construct() {
	
		//Constructeur

			//Ouverture et definition des valeur par défaut du fichier de configuration
			if(!$this->openConfFile()) {
				$this->_conf['links'] = array(
															'linuxFR'			=> 'http://linuxfr.org',
															'SDZ'					=> 'http://siteduzero.com',
															'Mosquit'		=> 'http://mosquit.net',
															'Puzzle Project'		=> 'http://puzzleproject.mosquit.net'
															);
				$this->_conf['foot'] = 'Zlog &amp; Puzzle Project<br/>Aucun droit réservé ;)';
				$this->saveConfFile();
			}
	
	}
	
	public function build() {
		$tr = new ZzTranslation('zlog');
		/*$signature = getenv("HTTP_USER_AGENT"); 
		if(preg_match('!MSIE [0-7]!',$signature))
			$return  = '
				<div id="alert"><p class="right">Merci de faire une mise à niveau vers firefox</p><p>Votre navigateur semble trop ancien. Les pages de ce blog risque de ne pas s afficher correctement</p></div>';
		else*/
			$return = '';
		$return .= '
		<div id="cmd">';		
		if(LabelIsWritable())
				$return .= '
				<div class="button"><a href="'.ZzGetUrl::theOtherPuZZle().'">Éditer</a></div>';
		foreach($this->_autoCreateChildrenRules as $val => $rule) {
			if($rule['all'] or in_array($rule['group'],$_SESSION['group']) or $rule['user'] == $_SESSION['user'])
				$return .= '
				<div class="button"><a href="'.ZzGetUrl::childLabel('{'.$val.'}',true).'">'.$tr->tr('New '.$val).'</a></div>';
		}
		$return .= '
		</div>';
		return $return;
	}

	public function buildStatic() {
		
		$this->_autoCreateChildrenRules = $this->getIO()->getAutoCreateChildrenRules();

		$this->store('_autoCreateChildrenRules');
		
		//Ajout des feuille de styles
		if($this->page != null) {
			$this->page->setMainCSS('zlog.css');
		}
		

		//Définition des liens de la linkbar
		foreach($this->_conf['links'] as $key => $val) {
			if(isSet($links))
				$links .= ' | ';
			else
				$links = ''; 
			$links .= '<a href="'.$val.'">'.$key.'</a>';
		}
		
		$menu = '';
		
		//Le menu
			//On récupère le chemin
				$i = 0;
				$_label = explode('-',$_GET['label']);
				$_label = array_reverse($_label);
				foreach($_label as $idLabel) {
					if(isSet($path))
						$path = $idLabel.'-'.$path;
					else
						$path = $idLabel;
					$io = ZzIO::getCleanedInstance($idLabel);
					$io->need('id');
					$io->need('name');
					if($i == 0)
						$menu .= '<a href="./?label='.$path.'">'.$io->get('name')->value.'</a>';
					else
						$menu .= ' &gt;&gt; <a href="./?label='.$path.'">'.$io->get('name')->value.'</a>';
					$i++;
					$io->dontNeed('id');
				}
			//On récupère les rubrique contenue dans cette rubrique
				foreach($this->getIO()->getAllChildren('category') as $label) {
					if(!isSet($ssMenu))
						$ssMenu = '';
					else
						$ssMenu .= ', ';
						$label->need('id');
						$label->need('name');
					$ssMenu .= '<a href="./?label='.$label->get('id')->value.'-'.$_GET['label'].'">'.$label->get('name')->value.'</a>';

				}
				if(!empty($ssMenu))
					$menu .= ' &gt;&gt; [ '.$ssMenu.' ]';
					
		$return = array();
		$return['menu'] = $this->openPhpFile('Zlog_LinkBar_MenuLogin').' '.$links;
		$return['navigation'] = $menu;
		$return['inner'] = $this->inner.$this->Me();
		$return['foot'] = $this->_conf['foot'];
		return $return;
  }
}
?>